<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" 		uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜系类别管理页面</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>

<script type="text/javascript">

	var url;

	function deleteBlogType(){
		var selectedRows=$("#dg").datagrid("getSelections");
		if(selectedRows.length==0){
			 $.messager.alert("系统提示","请选择要删除的数据！");
			 return;
		 }
		 var strIds=[];
		 for(var i=0;i<selectedRows.length;i++){
			 strIds.push(selectedRows[i].id);
		 }
		 var ids=strIds.join(",");
		 $.messager.confirm("系统提示","您确定要删除这<font color=red>"+selectedRows.length+"</font>条数据吗？",function(r){
				if(r){
					$.post("${pageContext.request.contextPath}/delUser",{ids:ids},function(result){
						if(result.success){
							if(result.exist){
								 $.messager.alert("系统提示",result.exist);
							}else{
								 $.messager.alert("系统提示","数据已成功删除！");								
							}
							 $("#dg").datagrid("reload");
						}else{
							$.messager.alert("系统提示","数据删除失败！");
						}
					},"json");
				} 
	   });
	}
	
	function openBlogTypeAddDialog(){
		$("#dlg").dialog({width:500,height:300});
		resetValue();
		$("#dlg").dialog("open").dialog("setTitle","添加用户");
		resetValue();
		url="${pageContext.request.contextPath}/addUser";
	}
	
	function openBlogTypeModifyDialog(){
		$("#dlg").dialog({width:500,height:300});
		var selectedRows=$("#dg").datagrid("getSelections");
		 if(selectedRows.length!=1){
			 $.messager.alert("系统提示","请选择一条要编辑的数据！");
			 return;
		 }
		 var row=selectedRows[0];
		 $("#dlg").dialog("open").dialog("setTitle","编辑用户信息");
		 $("#fm").form("load",row);
		 url="${pageContext.request.contextPath}/editUser";
	 }
	
	function saveBlogType(){
		 $("#fm").form("submit",{
			url:url,
			onSubmit:function(){
				return $(this).form("validate");
			},
			success:function(result){
				var result=eval('('+result+')');
				if(result.success){
					$.messager.alert("系统提示","保存成功！");
					resetValue();
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				}else{
					$.messager.alert("系统提示","保存失败！");
					return;
				}
			}
		 });
	 }
	
	function resetValue(){
		 $("#userRole").val("");
		 $("#id").val("");
		 $("#password").val("");
		 $("#userName").val("");
		 $("#gender").val("");
		 $("#tel").val("");
		 $("#email").val("");
		 $("#address").val("");
		 $("#birthdayString").val("");
	 }
	
	 function closeBlogTypeDialog(){
		 $("#dlg").dialog("close");
		 resetValue();
	 }

	 function searchMenu(){
			$("#dg").datagrid('load',{
				"menu.name":$("#s_menuName").val()
			});
		}
	 
	 function formatRole(val,row){
			if(val==1){
				return "<font>普通客户</font>";
			}
			if(val==2){
				return "<font color='green'>VIP用户</font>";
			}
			if(val==3){
				return "<font color='#A020F0'>服务员</font>";
			}
			if(val==4){
				return "<font color='red'>管理员</font>";
			}
		}
	 
	 function formatGender(val,row){
			if(val==0){
				return "<font>男</font>";
			}
			if(val==1){
				return "<font>女</font>";
			}
			
		}
	 function chooseOne(cb) {   
		var obj = document.getElementById("ChooseGender");   
			for (i=0; i<obj.children.length; i++){   
				if (obj.children[i]!=cb)
					obj.children[i].checked = false;   
				else obj.children[i].checked = true;   
			}   
		}
</script>
</head>
<body style="margin: 1px">
<table id="dg" title="菜品管理" class="easyui-datagrid"
   fitColumns="true" pagination="true" rownumbers="true"
   url="${pageContext.request.contextPath}/userlist" fit="true" toolbar="#tb">
   <thead>
   	<tr>
   		<th field="cb" checkbox="true" align="center"></th>
   		<th field="userRole" width="35" align="center" formatter="formatRole">用户权限</th>
   		<th field="id" width="35" align="center">用户Id</th>
   		<th field="password" width="35" align="center">密码</th>
   		<th field="userName" width="35" align="center" >名称</th>
   		<th field="gender" width="35" align="center" formatter="formatGender">性别</th>
   		<th field="tel" width="35" align="center">电话</th>
   		<th field="email" width="35" align="center">邮箱</th>
   		<th field="address" width="70" align="center">住址</th>
   		<th field="birthdayString" width="60" align="center">生日</th>
   		<th field="lastLockTimeString" width="60" align="center">最后登录时间</th>
   		<th field="loginFailCount" width="35" align="center">登录失败</th>
   	</tr>
   </thead>
 </table>
 <div id="tb">
 	<div>
 	    <a href="javascript:openBlogTypeAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
 		<a href="javascript:openBlogTypeModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
 		<a href="javascript:deleteBlogType()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
 	</div>
 	<div>
			&nbsp;用户名称：&nbsp;<input type="text" id="s_menuName" size="20" onkeydown="if(event.keyCode==13) searchMenu()"/>
			<a href="javascript:searchMenu()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
	</div>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
 </div>
 
 
 <div id="dlg" class="easyui-dialog" style="width:500px;height:180px;padding: 10px 20px"
   closed="true" buttons="#dlg-buttons">
   
   <form id="fm" method="post" enctype="multipart/form-data">
   	<table cellspacing="8px">
   	    <tr>
	 		<td>用户Id：</td>
	 		<td><input type="text" id="id" name="id" class="easyui-validatebox" required="true"/></td>
	 		</td>
	 	</tr>
   	    <tr>
   			<td>用户权限：</td>
   			<td>
   				<!-- <input type="text" id="userRole" name="userRole" class="easyui-validatebox" required="true"/> -->
   				<select type="text" id="userRole" name="userRole" class="easyui-validatebox" required="true" style="width: 154px">
   					<option value="1">普通客户</option>
   					<option value="2">VIP客户</option>
   					<option value="3">服务员</option>
   					<option value="4">管理员</option>
   				</select>
   			</td>
   		
   		</tr>
   		
   		<tr>
   			<td>密码：</td>
   			<td><input type="text" id="password" name="password" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>名称：</td>
   			<td><input type="text" id="userName" name="userName" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>性别：</td>
   			<td id="ChooseGender">
   				<!-- <input type="text" id="gender" name="gender" class="easyui-validatebox" required="true"/> -->
					<INPUT type="checkbox" id="gender" name="gender" required="true"  value="0" onClick="chooseOne(this)" checked="checked">男
					<INPUT type="checkbox" id="gender" name="gender" required="true"  value="1" onClick="chooseOne(this)">女
   			</td>
   		</tr>
   		<tr>
   			<td>电话：</td>
   			<td><input type="text" id="tel" name="tel" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>邮箱：</td>
   			<td><input type="text" id="email" name="email" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>住址：</td>
   			<td><input type="text" id="address" name="address" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>生日：</td>
   			<td><input type="text" id="birthdayString" name="birthdayString" class="easyui-datebox" value="2017-1-1" style="width:150px"/></td>
   		</tr>
   		<!--  
   		<tr>
   			<td>最后登录时间：</td>
   			<td><input type="text" id="lastLockTime" name="lastLockTime" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		<tr>
   			<td>登录失败：</td>
   			<td><input type="text" id="loginFailCount" name="loginFailCount" class="easyui-validatebox" required="true"/></td>
   		</tr>
   		
   		<tr>
	 		<td>商品图片：</td>
	 		<td colspan="4"><input type="file" id="image" name="image" /></td>
	    </tr>
   		-->
   		
   		
   	</table>
   </form>
 </div>
 
 <div id="dlg-buttons">
 	<a href="javascript:saveBlogType()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
 	<a href="javascript:closeBlogTypeDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
 </div>
</body>
</html>